<?php
class jsresponse
{
	function __construct()
	{
	}
	public function readMessages($Login)
	{
		$opts['sort'] = lib::returnField("sort");
		$opts['time']['time1'] = lib::returnField("time1");
		$opts['time']['time2'] = lib::returnField("time2");
		
		$data = db_messages::getMessages($opts);
		$num = 1;
		foreach ($data as $key => $entry)
		{
			echo "home".$num."#0#";
			display::fullMsg($entry);
			echo "|";
			$num++;
		}
	}
	public function voteMessage($userid, $action, $id)
	{
		if( $action == "up" )
		{
			$sql = "INSERT INTO vote (User_ID, Msg_ID) VALUES (%d,%d)";
			$query = sprintf($sql,
		            mysql_real_escape_string($userid),
					mysql_real_escape_string($id));
			$result = $this->mySql->makeQuery($query);
			
			$sql = " UPDATE Messages SET Rating = Rating + 1 WHERE Tbl_ID=%d ";
			$query = sprintf($sql,
						mysql_real_escape_string($id));
			$result = $this->mySql->makeQuery($query);
		}
		elseif( $action == "down" )
		{
			$sql = "INSERT INTO vote (User_ID, Msg_ID) VALUES (%d,%d)";
			$query = sprintf($sql,
		            mysql_real_escape_string($userid),
					mysql_real_escape_string($id));
			$result = $this->mySql->makeQuery($query);
			
			$sql = " UPDATE Messages SET Rating = Rating - 1 WHERE Tbl_ID=%d";
			$query = sprintf($sql,
						mysql_real_escape_string($id));
			$result = $this->mySql->makeQuery($query);
		}
		echo "DONE";
	}
	public function filterFeed($feed)
	{
		db_prefrences::changeFilter($feed);
	}
}